package com.jinzecloud.blog.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jinzecloud.blog.bean.Detail;
import com.jinzecloud.blog.bean.Tag;
import com.jinzecloud.blog.service.DetailService;
import com.jinzecloud.blog.utils.Page;
import com.jinzecloud.blog.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



/**
 * 文章详情 
 *
 * @author kumi
 * @email 1971240051@qq.com
 * @date 2022-06-04 03:23:06
 */
@RestController
@RequestMapping("article/detail")
public class DetailController {

    @Autowired
    DetailService detailService;

    @RequestMapping("/add")
    public Result addTag(@RequestBody Detail detail){
        try{
            detailService.add(detail);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(500,"添加失败");
        }

        return Result.ok().put("200","添加成功");
    }

    @RequestMapping("/update")
    public Result updateDetail(@RequestBody Detail detail){
        try{
            detailService.updateDetail(detail);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(500,"修改失败");
        }

        return Result.ok().put("200","修改成功");
    }

    @RequestMapping("/delete")
    public Result deleteDetail(@RequestBody Long[] ids){
        try{
            detailService.deleteDetail(ids);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(500,"删除失败");
        }

        return Result.ok().put("200","删除成功");
    }

    @RequestMapping("/getById/{id}")
    public Result getById(@PathVariable("id") Long id){
        Detail detail = null;
        try{
            detail = detailService.getByIdDetail(id);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(500,"查询失败");
        }

        return Result.ok().put("data",detail);
    }

    @RequestMapping("/getAll")
    public Result getAll(){
        Page<Detail> page = null;
        try{
            page = detailService.getAllDetail();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(500,"查询失败");
        }

        return Result.ok().put("data",page);
    }
}
